
package com.insigma.business.qrcode.soldier._provider.impl;

import com.insigma.business.qrcode.common._provider.BaseProviderImpl;
import com.insigma.business.qrcode.common.util.BizCheckUtil;
import com.insigma.business.qrcode.common.util.RedisUtils;
import com.insigma.business.qrcode.common.util.ResponseUtils;
import com.insigma.business.qrcode.common.vo.BaseResponse;
import com.insigma.business.qrcode.soldier.dto.SoldierApplyCheckDTO;
import com.insigma.business.qrcode.soldier.dto.SoldierApplyCheckInsertRequest;
import com.insigma.business.qrcode.soldier.entity.SoldierApplyCheckDO;
import com.insigma.business.qrcode.soldier._provider.SoldierApplyCheckProvider;
import com.insigma.business.qrcode.soldier.service.SoldierApplyCheckService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;


@Slf4j
@Service
@Component("soldierApplyCheckProvider")
public class SoldierApplyCheckProviderImpl extends BaseProviderImpl implements SoldierApplyCheckProvider {

    @Autowired
    private SoldierApplyCheckService soldierApplyCheckService;
    @Autowired
    private RedisUtils redisUtils;
    private Integer maxApplyCount = 5;


    @Transactional
    @Override
    public BaseResponse<String> insertSoldierApplyCheck(SoldierApplyCheckInsertRequest request) {

        BizCheckUtil.checkNotNull(request, "request的请求参数不能为空");
        BizCheckUtil.checkNotNull(request.getApplyId(), "applyId不能为空");
        BizCheckUtil.checkNotNull(request.getLevel(), "审批层级不能为空");
        BizCheckUtil.checkNotNull(request.getStatus(), "审批状态不能为空");
        BizCheckUtil.checkNotBlank(request.getCreatorName(), "审批人不能为空");

        final SoldierApplyCheckDO soldierApplyCheckDO = new SoldierApplyCheckDO();
        BeanUtils.copyProperties(request,soldierApplyCheckDO);
        soldierApplyCheckService.insert(soldierApplyCheckDO);
        return ResponseUtils.buildSuccessResponse(soldierApplyCheckDO.getId());
    }

    @Override
    public BaseResponse<List<SoldierApplyCheckDTO>> getSoldierApplyCheckInfo(Long applyId) {
        BaseResponse<List<SoldierApplyCheckDTO>> baseResponse = new BaseResponse();
        BizCheckUtil.checkNotNull(applyId, "请求参数不能为空");
        List<SoldierApplyCheckDO> list =  soldierApplyCheckService.search(applyId);
        List<SoldierApplyCheckDTO> listDto= new ArrayList<>();
       // BeanUtils.copyProperties(listDto,list);
        for (SoldierApplyCheckDO soldierApplyCheckDO : list){
            SoldierApplyCheckDTO soldierApplyCheckDTO = new SoldierApplyCheckDTO();
            BeanUtils.copyProperties(soldierApplyCheckDO, soldierApplyCheckDTO);
            listDto.add(soldierApplyCheckDTO);
        }
        return ResponseUtils.buildSuccessResponse(listDto);
    }

    @Override
    public BaseResponse<Integer> deleteByApplyId(String applyId) {
        BizCheckUtil.checkNotNull(applyId, "applyId不能为空");
        Integer count = soldierApplyCheckService.delete(applyId);
        return ResponseUtils.buildSuccessResponse(count);
    }


}
